if (localStorage.getItem("login") == 'false') {
  console.log(111);
  var acc = localStorage.getItem("user");
  $('#dl').html(acc)
}

let tc=document.getElementById("tc")
let aa=document.getElementById("dl")
let zc = document.getElementById("zc")
console.log(localStorage.getItem("login"));
function name1() {
    if(localStorage.getItem("login")!=false){
        zc.style.display = "none";
        
        tc.style.display="block";
    }else{
        zc.style.display ="block"
    }
    
}
name1()
tc.onclick=function(){
  dl.style.display="none";
  zc.style.display="block";
}
$(function(){
    // 下载app
    $('#apps').hover(function(){
        $('#app').slideToggle()
    });
    // 购物车
    $('#cart').hover(function(){
        console.log(123);
        $('#cars').slideToggle()
    });
    // hotgoods
    $('.mainbav-list li').hover(function(){
        $(this).find('div').stop().slideToggle()
    });
    
})
let id = localStorage.getItem("id");
// 详情页数据渲染
const pid = location.search.slice(4).trim();//获取商品的编号
localStorage.setItem("pid" ,pid)
console.log(pid);
// console.log(id);
$.ajax({
    type: "get",
    url:"http://jx.xuzhixiang.top/ap/api/detail.php",
      data: { id:pid
    },
       success: function (data) {
      console.log(data);
     let str=""
     str= `<img src="${data.data.pimg}"></img>
            `
     let mian1=document.querySelectorAll(".mian-l")
     console.log(mian1)
     mian1[0].innerHTML=str
  
   
     let srt2="";
     srt2=`
     <div class="pp" data-id=${data.data.pid}>
     <h2>${data.data.pname}</h2>
     <P>${data.data.pdesc}</P>
     <p>小米自营</p>
        </div>
          `
     let mian2=document.querySelectorAll(".pp")
     console.log(mian2)
     mian2[0].innerHTML=srt2

     let str3="";
     str3=`
      <div class="goodsxinxi">
      <p>名称:<span>${data.data.pname}</span></p>
      <p>总计:<span>${data.data.pprice}</span>元</p>
    </div>
          `
 let xinxi=document.querySelectorAll(".goodsxinxi")
 console.log(xinxi)
 xinxi[0].innerHTML=str3
    }
   
})


let btn=document.getElementById("btn")
btn.onclick=function(){
 
 $.ajax({
   type: "get",
   url: "http://jx.xuzhixiang.top/ap/api/add-product.php",
   data: {
     uid:localStorage.getItem("id"),
     pid:pid,
     pnum:1
   },
   dataType: "dataType",
   success: function (response) {
     alert("添加成功")
    
   }
 });
    location.href="购物车.html?id"+id
    
     }
console.log(id);

//小购物车
$.ajax({
  url: "http://jx.xuzhixiang.top/ap/api/cart-list.php",
  type: "get",
  data: {
      id: localStorage.getItem("id"),
      
      
  },
  success: function (data) {
      
      console.log(data);
      let str=""
      for(let key in data.data){
          str+=`
      
      <img src="${data.data[key].pimg}">
      <p class="pname">${data.data[key].pname}</p>
      <p>${data.data[key].pprice}</P>
      <p>${data.data[key].pnum}</P>
     
       `
      } 
      
      
     
    $("#cars").html(str)
  }
 
})

console.log("姬寅飞")
